/*
 * Copyright 2010 Christoph Widulle (christoph.widulle@googlemail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */



package com.android1.amarena2d.commons;

public class BottomLeftRectF {

    public float left;
    public float top;
    public float right;
    public float bottom;

    public BottomLeftRectF() {
    }

    public BottomLeftRectF(float left, float top, float right, float bottom) {
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
    }

    public BottomLeftRectF(BottomLeftRectF r) {
        left = r.left;
        top = r.top;
        right = r.right;
        bottom = r.bottom;
    }

    public BottomLeftRectF(Rect r) {
        left = r.left;
        top = r.top;
        right = r.right;
        bottom = r.bottom;
    }

    public String toString() {
        return "BottomLeftRectF(" + left + ", " + top + ", "
                + right + ", " + bottom + ")";
    }


    public final boolean isEmpty() {
        return left >= right || bottom >= top;
    }

    public final float width() {
        return right - left;
    }

    public final float height() {
        return top - bottom;
    }

    public final float centerX() {
        return (left + right) * 0.5f;
    }

    public final float centerY() {
        return (top + bottom) * 0.5f;
    }

    public void setEmpty() {
        left = right = top = bottom = 0;
    }

    public void set(float left, float top, float right, float bottom) {
        this.left = left;
        this.top = top;
        this.right = right;
        this.bottom = bottom;
    }


    public void set(BottomLeftRectF src) {
        this.left = src.left;
        this.top = src.top;
        this.right = src.right;
        this.bottom = src.bottom;
    }

    public int containsX(float x) {
        if (x < left) {
            return -1;
        }
        if (x > right) {
            return 1;
        }
        return 0;
    }

    public int containsY(float y) {
        if (y > top) {
            return 1;
        }
        if (y < bottom) {
            return -1;
        }
        return 0;
    }

    public boolean contains(float x, float y) {
        return x >= left && x <= right && y <= top && y >= bottom;
    }


    public boolean contains(float left, float top, float right, float bottom) {
        return this.left <= left && this.top >= top
                && this.right >= right && this.bottom <= bottom;
    }


    public boolean intersects(float left, float top, float right,
                              float bottom) {
        return this.left < right && left < this.right
                && this.top > bottom && top > this.bottom;
    }


    public void round(Rect dst) {
        dst.set(Math.round(left), Math.round(top),
                Math.round(right), Math.round(bottom));
    }


    public void roundOut(Rect dst) {
        dst.set((int) Math.floor(left), (int) Math.floor(top),
                (int) Math.ceil(right), (int) Math.ceil(bottom));
    }


}